package com.lihongman.dao;

import java.sql.ResultSet;
import java.sql.SQLException;

import com.lihongman.entity.Daoyou;
import com.lihongman.util.DBHelp;
import com.lihongman.util.RowMapper;

public class DaoyouDao {
	
	private DBHelp<Daoyou> db = new DBHelp<Daoyou>();
	public Daoyou findByName(String daoyou) {
		String sql = "select daoyou_id,name,tel from t_daoyou where name=?";
		return db.executeQueryForObject(sql, new DaoyouRowMapper(), daoyou);
	}

	public void save(Daoyou dyou) {
		String sql = "insert into t_daoyou(daoyou_id,name,tel) values(?,?,?)";
		db.executeSQL(sql, dyou.getId(),dyou.getName(),dyou.getTel());
		
	}
	private class DaoyouRowMapper implements RowMapper<Daoyou>{
		public Daoyou mapperRow(ResultSet rs) throws SQLException{
			Daoyou daoyou = new Daoyou();
			daoyou.setId(rs.getString("daoyou_id"));
			daoyou.setName(rs.getString("name"));
			daoyou.setTel(rs.getString("tel"));
		
			return daoyou;
			
		}
	}
	
}
